package com.cloudtasks;

import com.cloudtasks.R;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

/**
 * @author Administrator
 *
 */
public class AddItemByBrowsingPage1Activity extends Activity {
	
	String UserName = "";
	long UserID;
	String ListName = "";
	long ListID;
	final Context myContext = this;
	private Cursor DBcursor;
	final static String TYPE_PAGE = "type";
	private Database mDb;
	
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab_list_typepage);
        
        try{            	             	
	        // initialize the Database for this context
	        mDb = new Database(this);
	        mDb.open();
	        ListView lv = (ListView) findViewById(R.id.types_listview);
	        DBcursor = mDb.fetchAllItemTypesByList(ListID);
	        String[] categories = getResources().getStringArray(R.array.categories_array);
        	lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, categories));
	        startManagingCursor(DBcursor);
	        
	        // what happens when you click one entry in the ListView
	        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {  
				@Override
				public void onItemClick(AdapterView<?> av, View view,
						int pos, long id) {
	        		String name = ((TextView) view).getText().toString();
	        		//MyTools.displayToastMessage(myContext, name); 
	        		Intent intent = new Intent(myContext, AddItemByBrowsingPage2Activity.class);
					intent.putExtras(getIntent().getExtras());
					intent.putExtra("tname", name);
					TabGroupActivity parentActivity = (TabGroupActivity)getParent();
					parentActivity.startChildActivity("AddItemByBrowsingPage2Activity", intent);
				}  
	        });  
        }
        catch(Exception e){
        	MyTools.displayToastMessage(myContext, e.toString());
        }
    }
    public void onDestroy() {
        super.onDestroy();    
        mDb.close();
    }
}
